/*
 * FaciPara.java
 *
 * Created on May 24, 2005, 8:56 PM
 */

package aa.drivers;

import aa.core.ActorMessage;
import aa.core.ActorName;
import aa.core.Contract;
import aa.core.FacilitatorActor;
import aa.core.CyberOrg;
import java.util.LinkedList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author  xinghuizhao
 */
public class FaciPara extends FacilitatorActor{
    
    /** Creates a new instance of FaciPara */
    public FaciPara(CyberOrg p_cyb,Long parameter) {
        super(p_cyb);
    }
    
     /**
     *  This method is called in remote migration , when a cyberorg
      is migrating to this facilitator's host

     * @param p_conContract The contract which is held by the coming cyberorg
     * @param p_LECash The number of eCash
     * @param p_llActors Actor list of the coming cyberorg
     * @return The facilitator of the coming cyberorg
     */
    @Override
    public ActorName receiveCyberOrg(Contract p_conContract,Long p_LECash,LinkedList p_llActors){
        CyberOrg migrating = null;
        try{
            migrating = (CyberOrg)call((ActorName)p_llActors.get(0),"getHost");
            System.out.println("migrating....bla"+p_llActors.size());
            migrating.printInfo();

        }catch (Exception e){

        }
        
        

        setHost();
        for (int i=0;i<migrating.getActors().size();i++){
            migrating.updateActors((ActorName)migrating.getActors().get(i));
            System.out.println("actors "+((ActorName)migrating.getActors().get(i)).getUAN()+" host:"+((ActorName)migrating.getActors().get(i)).getHostAddress()+" LAN:"+((ActorName)migrating.getActors().get(i)).getLocationAddress());
        }
        m_cybHost.receiveCyberOrg(p_conContract,p_LECash,p_llActors,migrating);

        System.out.println("recived cyberorg: "+System.currentTimeMillis());
        
        return (ActorName)p_llActors.get(0);
    }
    
}
